package teach.shuji.java12.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import teach.shuji.java12.system.dto.LoginModel;
import teach.shuji.java12.system.dto.LoginResult;
import teach.shuji.java12.system.enums.LoginStatus;
import teach.shuji.java12.system.service.AccountService;

@Controller
@RequestMapping("account")
@RestController
public class AccountController {
    @Autowired
    AccountService accountService;

    @ApiOperation("用户登录")

    @PostMapping("login")
    public LoginResult login(@RequestBody LoginModel loginModel, HttpServletRequest request)
    {
        loginModel.setIp(request.getRemoteAddr());
        return accountService.login(loginModel);
    }

    @PostMapping("logout")
    public boolean logout(){
        StpUtil.logout();
        return true;
    }

}
